//nav导航的鼠标经过效果
(function () {
    const lis = document.querySelectorAll(`#hd .nav ul li`)
    for (let i = 0; i < lis.length; i++) {
        lis[i].addEventListener(`mouseenter`, function (e) {
            const act = document.querySelector(`#hd .nav ul li .active-i`)
            if (act) {
                act.classList.remove(`active-i`)
            }
            lis[i].children[1].classList.add(`active-i`)
        })
    }
})();
//登录注册交互
(function(){
    //获取登录和注册按钮
    const login = document.querySelector(`#userMenu a`)
    const register =login.nextElementSibling
    //获取遮罩层，登录注册界面
    const shade = document.querySelector(`.shade`)
    const login_index = document.querySelector(`.login_index`)
    const register_index = document.querySelector(`.register_index`)
    //获取关闭按钮
    const x = document.querySelectorAll(`.clear_x`)
    //登录注册点击打开事件
    login.addEventListener(`click`, function(e){
        e.preventDefault()
        shade.style.display = `block`
        login_index.style.display = `block`
        outError()
    })
    register.addEventListener(`click`, function(e){
        e.preventDefault()
        shade.style.display = `block`
        register_index.style.display = `block`
        outError()
    })
    //登录注册关闭界面事件
    for (let i = 0; i < x.length; i++) {
        x[i].addEventListener(`click`,function(){         
               shade.style.display = `none`
               this.parentNode.parentNode.style.display = `none`
       })
    }
    //登录注册界面交互事件
      //立即注册事件
    const nowReg = document.querySelectorAll(`.nowReg`)
    for (let i = 0; i < nowReg.length; i++) {
        nowReg[i].addEventListener(`click`,function(e){
            e.preventDefault()          
            shade.style.display = `block`
            login_index.style.display = `none`
            register_index.style.display = `block`
            reset_index.style.display = `none`
            note_index.style.display = `none`
            outError()
        })
    }   
      //已注册，去登录事件
    const goLogin = document.querySelectorAll(`.goLogin`)
    for (let i = 0; i < goLogin.length; i++) {
        goLogin[i].addEventListener(`click`,function(e){
            e.preventDefault()      
            shade.style.display = `block`
            register_index.style.display = `none`
            login_index.style.display = `block`
            reset_index.style.display = `none`
            note_index.style.display = `none`
            outError()
        })
    }  
      //忘记密码事件
    const getBack = document.querySelectorAll(`.getBack`)
    const reset_index = document.querySelector(`.reset_index`)
    const note_index = document.querySelector(`.note_index`)
    for (let i = 0; i < getBack.length; i++) {
        getBack[i].addEventListener(`click`,function(e){
            e.preventDefault()      
            shade.style.display = `block`
            register_index.style.display = `none`
            login_index.style.display = `none`
            reset_index.style.display = `block`
            note_index.style.display = `none`
            outError()
        })
    }
   
      //短信登录事件
    const noteLogin = document.querySelector(`.noteLogin`)
    noteLogin.addEventListener(`click`,function(e){
        e.preventDefault()      
        shade.style.display = `block`
        register_index.style.display = `none`
        login_index.style.display = `none`
        reset_index.style.display = `none`
        note_index.style.display = `block`
        outError()
    })
    //密码登录事件
    const codeLogin = document.querySelector(`.codeLogin`)
    codeLogin.addEventListener(`click`,function(e){
        e.preventDefault()      
        shade.style.display = `block`
        register_index.style.display = `none`
        login_index.style.display = `block`
        reset_index.style.display = `none`
        note_index.style.display = `none`
        outError()
    })
    //input失去焦点事件
    const inp_sr = document.querySelectorAll(`body .inp_sr`)
    for (let i = 0; i < inp_sr.length; i++) {
        inp_sr[i].addEventListener(`blur`,function(){
            this.style.borderColor = `#ff323e`
            this.parentNode.nextElementSibling.style.opacity = 1
        })
    }
    //input焦点初始化
    function outError(){
        for (let i = 0; i < inp_sr.length; i++) {
            inp_sr[i].style.borderColor = `#ededed`
            inp_sr[i].parentNode.nextElementSibling.style.opacity = 0
        }
    }
})();
//侧边栏
(function(){
    //二维码显示
    const scan = document.querySelector(`.scan`)
    const qrcode = document.querySelector(`.qrcode`)
    scan.addEventListener(`mouseenter`,function(){
        qrcode.style.display = `block`
    })
    scan.addEventListener(`mouseleave`,function(){
        qrcode.style.display = `none`
    })
    //返回顶部显示
    const ico_top = document.querySelector(`.ico_top`)
    const main_picture = document.querySelector(`.main_picture`)
    window.addEventListener(`scroll`, function(){
        const n = this.document.documentElement.scrollTop
        if (n >= main_picture.offsetTop) {
            ico_top.style.display = `block`
          } else {
            ico_top.style.display = `none`
          }
    })
})();

